export async function setAppLoginType() {
	let appLoginTypeList = ["apple", "weixin"];

	// #ifdef APP-PLUS
	await new Promise((cbFun) => {
		plus.oauth.getServices(servicesList => {
			appLoginTypeList = appLoginTypeList.filter(currentType => {
				if (["weixin", "apple", "univerify"].includes(currentType)) {
					let index = servicesList.findIndex(e => e.id == currentType)
					if (index == -1) {
						return false
					} else {
						return servicesList[index].nativeClient
					}
				} else {
					return true
				}
			})

			// iOS13+ 增加苹果登录
			uni.getSystemInfo({
				success: (result) => {
					if (result.system && result.system.split(' ')[1] >= 13 && result.platform ===
						'ios' && appLoginTypeList.indexOf('apple') === -1) {
						appLoginTypeList.push('apple')
					}
				}
			})

			cbFun();
		}, error => {
			console.error('获取服务列表失败：' + JSON.stringify(error));
		})
	})
	// #endif

	// #ifndef APP-PLUS
	appLoginTypeList = appLoginTypeList.filter(currentType => {
		return ![
			'univerify',
			'apple',
			// #ifdef H5
			'weixin'
			// #endif
		].includes(currentType)
	})
	// #endif
	
	console.log("appLoginTypeList a:", appLoginTypeList)

	let loginTypeTxt = appLoginTypeList.map(currentType => {
		let typeName = currentType
		let typeObj = {}
		typeObj.typeName = typeName;
		typeObj.text = (
			currentType === 'apple' ? 'iOS' :
			currentType === 'username' ? '帐密' :
			currentType === 'smsCode' ? '手机' :
			currentType === 'weixin' ? '微信' :
			currentType === 'univerify' ? '手机' : '登陆'
		)
		return typeObj
	})

	return loginTypeTxt;
}